package edu.guet.server.controller;

import edu.guet.server.model.vo.SubUnitVO;
import edu.guet.server.model.vo.SubunitResourceVO;
import edu.guet.server.model.vo.UnitVO;
import edu.guet.server.model.vo.UnitVO;
import edu.guet.server.service.ShowUnitService;
import edu.guet.server.utils.ResultAPI;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
@Slf4j
public class ShowUnitController {

    @Autowired
    private ShowUnitService unitService;

    /**
     *显示章节和内容
     * @param semester_id
     * @return
     */
    @GetMapping("/semesters/showunits")
    public ResultAPI showUnits(@RequestParam Long semester_id){
        //TODO 课程资源（全部）
        if (semester_id == null) {
            return ResultAPI.error("id为空！");
        }
        List<UnitVO> unitVO = unitService.showUnits(semester_id);
        return ResultAPI.success(unitVO);
    }

    /**
     * 显示小节标题及资源（教师端
     * @param unit_id
     * @return
     */
    @GetMapping("/unit/showSubsection")
    public ResultAPI showSubsection(@RequestParam Integer unit_id){
        if (unit_id == null) {
            return ResultAPI.error("id为空！");
        }
        SubUnitVO subunitVO=unitService.showSubUnitsandResource(unit_id);
        return ResultAPI.success(subunitVO);
    }

}
